import { createRouter, createWebHistory } from 'vue-router'
import Login from '../views/login/login.vue'

// 员工端路由
const employeeRoutes = [
  {
    path: '/employee',
    component: () => import('@/views/employee/layout.vue'),
    redirect: '/employee/medicine',
    children: [
      {
        path: 'medicine',
        component: () => import('@/views/employee/medicine.vue'),
        meta: { title: '药品信息维护' },
      },
      {
        path: 'stock',
        component: () => import('@/views/employee/stock.vue'),
        meta: { title: '药品出入库管理' },
      },
      {
        path: 'order',
        component: () => import('@/views/employee/order.vue'),
        meta: { title: '订单管理' },
      },
    ],
  },
]

// 将员工路由添加到路由配置中
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: 'Login',
      component: Login,
    },
    {
      path: '/user',
      name: 'UserLayout',
      component: () => import('../views/user/layout.vue'),
      redirect: '/user/home',
      children: [
        {
          path: 'home',
          name: 'UserHome',
          component: () => import('../views/user/home.vue'),
        },
        {
          path: 'profile',
          name: 'UserProfile',
          component: () => import('../views/user/profile.vue'),
        },
        {
          path: 'medicine',
          name: 'UserMedicine',
          component: () => import('../views/user/medicine.vue'),
        },
        {
          path: 'cart',
          name: 'UserCart',
          component: () => import('../views/user/cart.vue'),
        },
        {
          path: 'order',
          name: 'UserOrder',
          component: () => import('../views/user/order.vue'),
        },
        {
          path: 'address',
          name: 'UserAddress',
          component: () => import('../views/user/address.vue'),
        },
      ],
    },
    {
      path: '/admin',
      name: 'AdminLayout',
      component: () => import('../views/admin/layout.vue'),
      redirect: '/admin/user',
      children: [
        {
          path: 'user',
          name: 'AdminUser',
          component: () => import('../views/admin/user.vue'),
        },
        {
          path: 'employee',
          name: 'AdminEmployee',
          component: () => import('../views/admin/employee.vue'),
        },
        {
          path: 'medicine',
          name: 'AdminMedicine',
          component: () => import('../views/admin/medicine.vue'),
        },
        {
          path: 'category',
          name: 'AdminCategory',
          component: () => import('../views/admin/category.vue'),
        },
        {
          path: 'stock',
          name: 'AdminStock',
          component: () => import('../views/admin/stock.vue'),
        },
      ],
    },
    ...employeeRoutes,
  ],
})

export default router
